package lanou.autohome.recommend.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.recommend.beans.OriginalityVideoBean;

/**
 * Created by dllo on 16/8/19.
 */
public class OriginalityVideoAdapter extends RecyclerView.Adapter<OriginalityVideoAdapter.VideoViewHolder> {

    private Context mcontext;
    private OriginalityVideoBean originalityvideoBean;

    public OriginalityVideoAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setOriginalityvideoBean(OriginalityVideoBean originalityvideoBean) {
        this.originalityvideoBean = originalityvideoBean;
        notifyDataSetChanged();
    }

    @Override
    public VideoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mcontext).inflate(R.layout.item_recommend_originality_video, null);
        VideoViewHolder videoViewHolder = new VideoViewHolder(view);
        return videoViewHolder;
    }

    @Override
    public void onBindViewHolder(VideoViewHolder holder, int position) {

        holder.time.setText(originalityvideoBean.getResult().getList().get(position).getTime());
        holder.title.setText(originalityvideoBean.getResult().getList().get(position).getTitle());
        holder.replycount.setText(String.valueOf(originalityvideoBean.getResult().getList().get(position).getReplycount() + "播放"));

        NetTool netTool = new NetTool();
        netTool.getImage(originalityvideoBean.getResult().getList().get(position).getSmallimg(), holder.smallpic);

    }

    @Override
    public int getItemCount() {
        return originalityvideoBean != null ? originalityvideoBean.getResult().getList().size() : 0;
    }


    public class VideoViewHolder extends RecyclerView.ViewHolder {
        ImageView smallpic;
        TextView title;
        TextView time;
        TextView replycount;

        public VideoViewHolder(View itemView) {
            super(itemView);
            smallpic = (ImageView) itemView.findViewById(R.id.smallpic_recommend_originalityvideo_item);
            title = (TextView) itemView.findViewById(R.id.title_recommend_originalityvideo_item);
            time = (TextView) itemView.findViewById(R.id.time_recommend_originalityvideo_item);
            replycount = (TextView) itemView.findViewById(R.id.replycount_recommend_originalityvideo_item);
        }
    }
}